<template>
  <div>
    <ProductionSelector
      ref="prod"
      v-model="valueField"
      @productionSelected="updateCell"
      @selectorVisiableChange="setEnterAction"
    />
  </div>
</template>
<script>
import Vue from 'vue'
import ProductionSelector from '@/components/Selector/ProductionSelector.vue'
import { getProduction } from '@/api/production'
export default {
  components: { ProductionSelector },

  data() {
    return {
      cancelBeforeStart: true,
      valueField: 0
    }
  },
  methods: {
    getValue() {
      return this.valueField
    },
    isCancelBeforeStart() {
      return this.cancelBeforeStart
    },
    updateCell(params) {
      this.valueField = params.AutoId
      this.textField = params.Name
      this.pickerVisible = false
      if (this.params.cellUpdateHandler) {
        this.params.cellUpdateHandler(params)
      }
    },
    setEnterAction(params) {
      if (this.params.selectVisableChange) {
        this.params.selectVisableChange(params)
      }
    }
  },
  created() {
    this.valueField = this.params.value
    //this.selected.push(this.valueField)
    getProduction(this.params.value)
      .then(response => {
        if (response.Result === 0) {
          this.textField = response.Data.Name
        } else {
          this.textField = '未知'
        }
      })
      .catch(error => {
        console.log(error)
      })
    this.cancelBeforeStart = false
  },
  mounted() {
    Vue.nextTick(() => {
      this.$refs.prod.focus()
    })
  }
}
</script>
